package com.ohos.carbon.slice;

import com.ohos.carbon.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.element.ElementScatter;
import ohos.utils.net.Uri;

public class AboutSlice extends AbilitySlice {
    private Text text_title;
    private Image back_button;
    DirectionalLayout websiteLayout, reportIssueLayout;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_activity_about);
        text_title = (Text) findComponentById(ResourceTable.Id_title_text);
        text_title.setText("About");
        back_button = (Image) findComponentById(ResourceTable.Id_back_button);
        back_button.setImageElement(ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_carbon_uparrow));
        //返回上个页面
        back_button.setClickedListener(component -> {
            onBackPressed();
        });

        websiteLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_website_layout);
        reportIssueLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_report_issue_layout);

        websiteLayout.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                String websiteUrl = "https://github.com/ZieIony/Carbon";
                Uri uri = Uri.parse(websiteUrl);
                Intent i = new Intent();
                i.setUri(uri);
                startAbility(i);
            }
        });

        reportIssueLayout.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                String reportUrl = "https://github.com/ZieIony/Carbon/issues";
                Uri uri = Uri.parse(reportUrl);
                Intent i = new Intent();
                i.setUri(uri);
                startAbility(i);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
